//
//  MbInit.m
//  MbAdsSdk
//
//  Created by 吴奶强 on 2021/12/6.
//

#import "MbInitAd.h"
#import <BUAdSDK/BUAdSDK.h>
#import "GDTSDKConfig.h"
#import <KSAdSDK/KSAdSDK.h>
#import <ABUADSDK/ABUADSDK.h>


@implementation MbInitAd


+ (instancetype)sharedManager {
    static MbInitAd *mbinit = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        mbinit = [self new];
    });
    return mbinit;
}




- (void)initConfig:(NSString *)ttId gdtId:(NSString *)gdtId ksId:(NSString *)ksId gromoreId:(NSString *)gromoreId successBlock:(SuccessBlock)successBlock errorBlock:(FailureBlock)errorBlock{
    
    if(gdtId.length != 0){
        [GDTSDKConfig registerAppId:gdtId];
    }
    if(ksId.length != 0){
        [KSAdSDKManager setAppId:ksId];
        // 根据需要设置⽇志级别
        [KSAdSDKManager setLoglevel:KSAdSDKLogLevelDebug];
         
    }
    if(gromoreId != 0){
        [ABUAdSDKManager setupSDKWithAppId:gromoreId config:^ABUUserConfig *(ABUUserConfig *config) {
            #if DEBUG
            config.logEnable = YES;
            #endif
            config.logEnable = NO;
           
            return config;
        }];
    }
    
    if(ttId.length != 0){
        BUAdSDKConfiguration *configuration = [BUAdSDKConfiguration configuration];
        configuration.territory = BUAdSDKTerritory_CN;
        configuration.GDPR = @(0);
        configuration.coppa = @(0);
        configuration.CCPA = @(1);
    #if DEBUG
        configuration.logLevel = BUAdSDKLogLevelVerbose;
    #endif
        configuration.appID = ttId;
        
        [BUAdSDKManager startWithAsyncCompletionHandler:^(BOOL success, NSError *error) {
            if (success) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    successBlock();
                });
            } else{
                dispatch_async(dispatch_get_main_queue(), ^{
                    NSLog(@"开屏初始化失败");
                    errorBlock(error);
                });
            }
        }];
    } else{
        successBlock();
    }
    
}





@end
